﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using D6.DFS.Consumer;
using System.Net;

namespace SessionCountingApp
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        protected DfsWrapper m_DfsWrapper = new DfsWrapper("DMS", "damadmin", "C@nwest1");

        public MainWindow()
        {
            InitializeComponent();
            populateRepositoryList();
        }

        protected void populateRepositoryList()
        {
            foreach (String repositoryName in m_DfsWrapper.Repositories)
            {
                m_RepositoryListBox.Items.Add(repositoryName);
            }
        }

        private void m_CountSessionsButton_Click(object sender, RoutedEventArgs e)
        {
            String repositoryUser = m_UsernameTextBox.Text;
            String repositoryPassword = m_PasswordTextBox.Text;

            if (String.IsNullOrEmpty(repositoryUser))
            {
                return;
            }
            if (String.IsNullOrEmpty(repositoryPassword))
            {
                return;
            }

            int selectedIndex = m_RepositoryListBox.SelectedIndex;

            if (selectedIndex < 0)
            {
                return;
            }

            String selectedRepository = m_RepositoryListBox.Items[selectedIndex].ToString();

            m_DfsWrapper.setCurrentRepository(selectedRepository, repositoryUser, repositoryPassword);

            int countOfDfcSessions = m_DfsWrapper.getOpenSessions();

            if (countOfDfcSessions < 0)
            {
                MessageBox.Show(m_DfsWrapper.ErrorMessage);
                return;
            }

            MessageBox.Show(countOfDfcSessions.ToString(), "Count of open DFC sessions:");

        }

    }
}
